package com.weetop.cfw.home_page.activity

import android.os.Bundle
import android.text.Editable
import android.view.View
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ColorUtils
import com.kongzue.dialog.v3.BottomMenu
import com.weetop.cfw.R
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.utils.PictureSelectorUtils
import kotlinx.android.synthetic.main.activity_warehouse_rental_publish.*


/**
 * 仓库租售发布界面
 */
class WarehouseRentalPublishActivity : CommonBaseActivity(), View.OnClickListener {

    override fun onClick(p0: View?) {
        when(p0?.id){
            R.id.imagePublishBack -> ActivityUtils.finishActivity(this)
            R.id.imageChoosePhotoLogo -> PictureSelectorUtils.openAlbumAndCamera(this,1)
            R.id.relativeWhetherSublease -> showWhetherSubleaseBottomMenu()
            R.id.relativeAloneCourtyard -> showAloneCourtyardBottomMenu()
            R.id.relativeHaveElevator -> showHaveElevatorBottomMenu()
            R.id.relativePublishSite -> showPublishSiteBottomMenu()
            R.id.relativeAddressDetail -> ActivityUtils.startActivityForResult(this,ChooseAddressActivity::class.java,0)
            R.id.relativeHouseLicense -> showHaveHouseLicenseBottomMenu()
            R.id.relativeLandLicense -> showHaveLandLicenseBottomMenu()
            R.id.relativeUsefulLife -> showUsefulLifeBottomMenu()
            R.id.relativeBuildType -> showBuildTypeBottomMenu()
        }
    }

    override fun getLayoutId() = R.layout.activity_warehouse_rental_publish

    override fun initView(savedInstanceState: Bundle?) {
        setViewsOnClickListener(this,imagePublishBack,imageChoosePhotoLogo,relativeWhetherSublease,relativeAloneCourtyard,relativeHaveElevator,relativePublishSite,relativeAddressDetail,relativeHouseLicense,relativeLandLicense,relativeUsefulLife,relativeBuildType)
    }

    override fun initData(savedInstanceState: Bundle?) {

    }

    /**
     * 展示厂房是否可以分租的底部对话框
     */
    private fun showWhetherSubleaseBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("可分租", "不可分租")
        ) { text, index ->
            textWhetherSublease.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textWhetherSublease.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示厂房是否是独院的底部对话框
     */
    private fun showAloneCourtyardBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("是", "否")
        ) { text, index ->
            textAloneCourtyard.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textAloneCourtyard.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示厂房是否有电梯的底部对话框
     */
    private fun showHaveElevatorBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("有电梯", "无电梯")
        ) { text, index ->
            textHaveElevator.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textHaveElevator.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示发布站点的底部对话框
     */
    private fun showPublishSiteBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("余杭区", "萧山区","拱墅区","上城区","下城区","富阳区","西湖区","滨江区","江干区")
        ) { text, index ->
            textPublishSite.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textPublishSite.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示是否有房产证的底部对话框
     */
    private fun showHaveHouseLicenseBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("有房产证", "无房产证")
        ) { text, index ->
            textHaveHouseLicense.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textHaveHouseLicense.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示是否有土地证的底部对话框
     */
    private fun showHaveLandLicenseBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("有土产证", "无土产证")
        ) { text, index ->
            textLandLicense.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textLandLicense.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示使用年限的底部对话框
     */
    private fun showUsefulLifeBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("一年", "两年","三年")
        ) { text, index ->
            textUsefulLife.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textUsefulLife.text = Editable.Factory.getInstance().newEditable(text)
        }
    }

    /**
     * 展示建筑类型选择的底部对话框
     */
    private fun showBuildTypeBottomMenu(){
        BottomMenu.show(
            this@WarehouseRentalPublishActivity,
            arrayOf("厂房", "仓库","办公楼","工业用地","场地","商务楼","抵押类工业用地")
        ) { text, index ->
            textBuildType.setTextColor(ColorUtils.getColor(R.color.colorAccent))
            //返回参数 text 即菜单名称，index 即菜单索引
            textBuildType.text = Editable.Factory.getInstance().newEditable(text)
        }
    }
}
